
import java.sql.*;
import java.util.ResourceBundle;

public class Main {
    public static void main(String[] args) {
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        ResourceBundle  resourceBundle =  ResourceBundle.getBundle("jdbc");
        String url   = resourceBundle.getString("url");
        String  driver = resourceBundle.getString("driver");
        String user = resourceBundle.getString("user");
        String password = resourceBundle.getString("password");


        try {
            // 注册驱动
            Class.forName(driver);

            // 获取链接
            connection = DriverManager.getConnection(url,user,password);

            // 获取对象
            statement = connection.createStatement();

            // 执行musql语句
            String sql = "select ename as name,sal as s from emp";

            resultSet = statement.executeQuery(sql);


            // 对查询结果集进行处理
            while (resultSet.next()){
                String name = resultSet.getString("name");
                int sal = resultSet.getInt("s");
                System.out.println(name+sal);

            }


        }catch (SQLException e){
            e.printStackTrace();
        }catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
    finally {
            try{
                if(statement!=null){
                    statement.close();
                }

            }catch (SQLException e){
                e.printStackTrace();
            }

            try{
                if(connection!=null){
                    connection.close();
                }
            }
            catch (SQLException e){
                e.printStackTrace();
            }
        }
    }
}